suppressMessages(library("lazyopt"))
spec <- matrix(c("tablepath", "i", 2, "character", "The path to the table data read", "",
                 "filepath", "o", 1, "character", "The package path of the output files", getwd(),
                 "scale", "sca", 1, "logical", "scale data", "TRUE"
), byrow = TRUE, ncol = 6)

opt <- lazyopt(spec,arg=c("-i","E:/projects/R_draw_sc/eror/pca/ko_table.txt","-o","E:/projects/R_draw_sc/eror/pca/data"))

setwd(opt$filepath)
da <- read.delim(opt$tablepath, check.names = FALSE, header = TRUE)
pca <- prcomp(t(da), scale = as.logical(opt$scale))
pvar <- pca$sdev^2
pvar <- round((pvar / sum(pvar)) * 100, 2)
pca12 <- pca$x
pca12 <- as.data.frame(pca12)
pvar <- paste0(pvar, "%")
pvar <- as.data.frame(pvar)
rownames(pvar) <- paste0("PCA", (1:nrow(pvar)))
names(pvar) <- NULL
write.table(x = pca12, file = "pca.x.xls", sep = "\t", col.names = NA)
write.table(x = pvar, file = "pca.sdev.xls", sep = "\t", col.names = NA)
write.table(x = pca$rotation, file = "pca.rotation.xls", sep = "\t", col.names = NA)
